﻿Public Class F_TKDoanhThu
    Sub loadhoadon()
        Dim sql As String = String.Format("select * from HOADON where NgayXuat between '{0}' and '{1}'", txtstart.Text, txtEnd.Text)
        gcHoadon.DataSource = DataProvider.LoadTable(sql)
    End Sub
    Private Sub F_TKDoanhThu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtstart.Text = DateAdd(DateInterval.Day, -60, Now.Date)
        txtEnd.Text = DateTime.Now
        gvBanan.DataSource = BUSBanAn.BanAn_Load
        gcMon.DataSource = BUSMonAn.MonAn_Load

    End Sub
 

    'monan.MaMA = gvMonAn.GetFocusedRowCellDisplayText("MaMA")
    'tb.MaBan = gvBanan.CurrentRow.Cells("MaBan").Value
    Dim tb As New DTOBanAn
    Private Sub btntkban_Click(sender As Object, e As EventArgs) Handles btntkban.Click


        Dim sql As String = String.Format("select * from HOADON where NgayXuat between '{0}' and '{1}' and TINHTRANG = 1 and  MaBan ={2}", txtstart.Text, txtEnd.Text, tb.MaBan)

        gcHoadon.DataSource = DataProvider.LoadTable(sql)
    End Sub

    Private Sub btntkmon_Click(sender As Object, e As EventArgs) Handles btntkmon.Click
        dim monan As New DTOMonAn
        monan.MaMA = gvMonAn.GetFocusedRowCellDisplayText("MaMA")
        Dim sql As String = String.Format("select h.MaHD,TenBan,NgayXuat,MaMA,TenMA,DonGia,SoLuong,ThanhTien from CTHOADON c, HOADON h where h.NgayXuat between '{0}' and '{1}' and h.TinhTrang =1 and h.MaHD = c.MaHD and c.MaMA ={2} ", txtstart.Text, txtEnd.Text, monan.MaMA)
        gcHoadon.DataSource = DataProvider.LoadTable(sql)
        'select h.MaHD,TenBan,NgayXuat,MaMA,TenMA,DonGia,SoLuong,ThanhTien from CTHOADON c, HOADON h where h.NgayXuat between '2010-12-20' and '2014-10-1' and h.TinhTrang =1 and h.MaHD = c.MaHD and c.MaMA =2 
    End Sub

    Private Sub gvBanan_SelectionChanged(sender As Object, e As EventArgs) Handles gvBanan.SelectionChanged
        tb.MaBan = gvBanan.CurrentRow.Cells("MaBan").Value
    End Sub

    Private Sub btnBaoCao_Click_1(sender As Object, e As EventArgs) Handles btnBaoCao.Click
        gcHoadon.ShowPrintPreview()
    End Sub
End Class